<section class="main">
    <div id="divMain">
        <div class="divHeader2">文章编辑</div>
        <div class="SubMenu"></div>
        <div id="divMain2" class="edit post_edit">
            <form action="/system/management/article-add.html" id="edit" name="edit" method="post">
                <div id="divEditLeft">
                    <!-- 4号输出接口 -->
                    <div id="response4" class="editmod2"></div>
                    <div id="divEditTitle" class="editmod2">
                        <input type="hidden" name="id" id="edtID" value="$!model.id" />
                        <input type="hidden" name="status" id="edtType" value="$!model.status" />
                        <!-- title( -->
                        <div id="titleheader" class="editmod">
                            <label for="edtTitle" class="editinputname" >标题</label>
                            <div><input type="text" name="title" id="edtTitle"  maxlength="100" onBlur="if(this.value=='') this.value='未命名'" onFocus="if(this.value=='未命名') this.value=''" value="$!model.title" /></div>
                        </div>
                        <!-- )title -->
                    </div>

                    <!-- 5号输出接口 -->
                    <div id="response5" class="editmod2"></div>
                    <div id="divContent"  class="editmod2" style="clear:both;">
                        <div id='cheader' class="editmod editmod3">
                            <label for="editor_content" class="editinputname" >正文</label>&nbsp;&nbsp;
                            <span id="timemsg"></span><span id="msg2"></span><span id="msg"></span><span class="editinputname" ></span>
                        </div>
                        <div id='carea' class="editmod editmod3"><textarea id="editor_content" name="content">$!model.content</textarea></div>
                        <div id="contentready" style="display:none"><img alt="loading" id="statloading1" src="/resources/system/image/admin/loading.gif"/>Waiting...</div>
                    </div>

                    <!-- 1号输出接口 -->
                    <div id="response" class="editmod2"></div>

                    <!-- alias( -->
                    <div id="alias" class="editmod2"><label for="edtAlias" class="editinputname" >别名</label>
                        <input type="text" name="alias" id="edtAlias" maxlength="250" value="$!model.alias" />
                    </div>
                    <!-- )alias -->
                    <!-- tags( -->
                    <div id="tags" class="editmod2"><label  for="edtTag"  class='editinputname'>标签</label>
                        <input type="text"  name="tags" id="edtTag" value="tag123" />
                        (逗号分割) <a href="#" id="showtags">显示常用标签</a></div>
                    <!-- Tags -->
                    <div id="ulTag" class="editmod2" style="display:none;">
                        <div id="ajaxtags">Waiting...</div>
                    </div>
                    <!-- )tags -->

                    <div id="insertintro" class="editmod2" style="padding-top:1em;paddding-bottom:0;"><span>* 在正文插入分隔符&quot;&lt;hr class=&quot;more&quot; /&gt;&quot;可以让系统识别摘要内容。如需另外指定摘要内容，请点击<a href="" onClick="try{AutoIntro();return false;}catch(e){}">[手动生成摘要]</a></span></div>

                    <div id="divIntro" class="editmod2" >
                        <div id="theader" class="editmod editmod3"><label for="editor_intro" class="editinputname" >摘要</label></div>
                        <div id='tarea' class="editmod editmod3"><textarea id="editor_intro" name="intro">$!model.intro</textarea></div>
                        <div id="introready" style="display:none"><img alt="loading" id="statloading2" src="/resources/system/image/admin/loading.gif"/>Waiting...</div>
                    </div>
                    <!-- 2号输出接口 -->
                    <div id="response2" class="editmod2"></div>

                </div>
                <!-- divEditLeft -->

                <div id="divEditRight">
                    <div id="divEditPost">
                        <div id="divBox">
                            <div id="divFloat">
                                <div id='post' class="editmod">
                                    <input class="button" style="width:180px;height:38px;" type="submit" value="提交" id="btnPost" onclick='return checkArticleInfo();' />
                                </div>

                                <!-- cate -->          <div id='cate' class="editmod"> <label for="cmbCateID" class="editinputname" style="max-width:65px;text-overflow:ellipsis;">分类</label>
                                <select style="width:180px;" class="edit" size="1" name="cateId" id="cmbCateID">
                                    <option selected="selected" value="$!model.cateId">$!model.cateId</option>
                                    <option selected="selected" value="1">1</option>
                                </select>
                            </div>
                                <!-- cate -->
                                <!-- level -->
                                <div id='level' class="editmod"> <label for="cmbPostStatus" class="editinputname" style="max-width:65px;text-overflow:ellipsis;">状态</label>
                                    <select class="edit" style="width:180px;" size="1" name="status" id="cmbPostStatus" onChange="edtLevel.value=this.options[this.selectedIndex].value">
                                        <option value="$!model.status" selected="selected" >$!model.status</option><option value="1"  >草稿</option><option value="2"  >审核</option>            </select>
                                </div>
                                <!-- )level -->

                                <!-- template( -->

                                <div id='template' class="editmod"> <label for="cmbTemplate" class="editinputname" style="max-width:65px;text-overflow:ellipsis;">模板</label>
                                    <select style="width:180px;" class="edit" size="1" name="template" id="cmbTemplate" onChange="edtTemplate.value=this.options[this.selectedIndex].value">
                                        <option value="" >无</option><option value="index" >index</option><option value="$!model.template" selected="selected">$!model.template</option>            </select>
                                </div>
                                <!-- )template -->

                                <!-- user( -->
                                <div id='user' class="editmod"> <label for="cmbUser" class="editinputname" style="max-width:65px;text-overflow:ellipsis;">作者</label>
                                    <select style="width:180px;" size="1" name="userId" id="cmbUser" onChange="edtAuthorID.value=this.options[this.selectedIndex].value">
                                        <option value="$!model.userId" selected="selected" >$!model.userId</option><option value="2"  >aooer</option>
                                    </select>
                                </div>
                                <!-- )user -->

                                <!-- newdatetime( -->
                                <div id='newdatetime' class="editmod"> <label for="edtDateTime" class="editinputname" style="max-width:65px;text-overflow:ellipsis;">日期</label>
                                    <input type="text" name="modifyTime" id="edtDateTime"  value="$!model.modifyTime" style="width:171px;"/>
                                </div>

                                <!-- )newdatetime -->

                                <!-- 3号输出接口 -->
                                <div id="response3" class="editmod">
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <!-- divEditRight -->
            </form>
        </div>

        <script type="text/javascript">ActiveLeftMenu("aArticleMng");</script>
        <script type="text/javascript">AddHeaderIcon("/resources/system/image/common/new_32.png");</script>
        <script type="text/javascript">

            var tag_loaded=false; //是否已经ajax读取过TAGS
            var sContent="",sIntro="";//原内容与摘要
            var isSubmit=false;//是否提交保存

            var editor_api={
                editor:	{
                    content:{
                        obj:{},
                        get:function(){return ""},
                        insert:function(){return ""},
                        put:function(){return ""},
                        focus:function(){return ""}
                    },
                    intro:{
                        obj:{},
                        get:function(){return ""},
                        insert:function(){return ""},
                        put:function(){return ""},
                        focus:function(){return ""}
                    }
                }
            }

            //文章内容或摘要变动提示保存
            window.onbeforeunload = function(){
                if (!isSubmit && (editor_api.editor.content.get()!=sContent)) return "当前的编辑内容还未保存";
            }

            function checkArticleInfo(){
                if(isSubmit)return false;

                if($("#editor_content").val()==null||$("#editor_content").val()==""){
                    alert('正文不能为空');
                    return false;
                }
                isSubmit=true;
            }

            //日期时间控件
            $.datepicker.regional['zh-CN'] = {
                closeText: '完成',
                prevText: '上个月',
                nextText: '下个月',
                currentText: '现在',
                monthNames: ['一月','二月','三月','四月','五月','六月','七月','八月','九月','十月','十一月','十二月'],
                monthNamesShort: ['1月','2月','3月','4月','5月','6月','7月','8月','9月','10月','11月','12月'],
                dayNames: ['星期日','星期一','星期二','星期三','星期四','星期五','星期六'],
                dayNamesShort: ['周日','周一','周二','周三','周四','周五','周六'],
                dayNamesMin: ['日','一','二','三','四','五','六'],
                weekHeader: '周',
                dateFormat: 'yy-mm-dd',
                firstDay: 1,
                isRTL: false,
                showMonthAfterYear: true,
                yearSuffix: ' 年  '
            };
            $.datepicker.setDefaults($.datepicker.regional['zh-CN']);
            $.timepicker.regional['zh-CN'] = {
                timeOnlyTitle: '时间',
                timeText: '时间',
                hourText: '小时',
                minuteText: '分钟',
                secondText: '秒钟',
                millisecText: '毫秒',
                currentText: '现在',
                closeText: '完成',
                timeFormat: 'HH:mm:ss',
                ampm: false
            };
            $.timepicker.setDefaults($.timepicker.regional['zh-CN']);
            $('#edtDateTime').datetimepicker({
                showSecond: true
                //changeMonth: true,
                //changeYear: true
            });


            //显示tags
            $(document).click(function (event){$('#ulTag').slideUp("fast");});

            $('#showtags').click(function (event) {
                event.stopPropagation();
                var offset = $(event.target).offset();
                $('#ulTag').css({ top: offset.top + $(event.target).height()+20+ "px", left: offset.left});
                $('#ulTag').slideDown("fast");
                if(tag_loaded==false){$.getScript('../cmd.php?act=misc&type=showtags');tag_loaded=true;}
                return false;
            });
            function AddKey(i) {
                var strKey=$('#edtTag').val();
                var strNow=","+i
                if(strKey==""){
                    strNow=i
                }
                if(strKey.indexOf(strNow)==-1){
                    strKey=strKey+strNow;
                }
                $('#edtTag').val(strKey);
            }
            function DelKey(i) {
                var strKey=$('#edtTag').val();
                var strNow="{"+i+"}"
                if(strKey.indexOf(strNow)!=-1){
                    strKey=strKey.substring(0,strKey.indexOf(strNow))+strKey.substring(strKey.indexOf(strNow)+strNow.length,strKey.length)
                }
                $('#edtTag').val(strKey);
            }

            //提取摘要
            function AutoIntro() {
                var s=editor_api.editor.content.get();
                if(s.indexOf("<hr class=\"more\" />")>-1){
                    editor_api.editor.intro.put(s.split("<hr class=\"more\" />")[0]);
                }else{
                    if(s.indexOf("<hr class=\"more\"/>")>-1){
                        editor_api.editor.intro.put(s.split("<hr class=\"more\"/>")[0]);
                    }else{
                        editor_api.editor.intro.put(s.substring(0,250));
                    }
                }
                $("#divIntro").show();
                $('html,body').animate({scrollTop:$('#divIntro').offset().top},'fast');
            }

            //文章编辑提交区随动JS开始
            var oDiv=document.getElementById("divFloat");
            var H=0;var Y=oDiv;
            while(Y){H+=Y.offsetTop;Y=Y.offsetParent;};
            $(window).bind("scroll resize",function(){
                var s=document.body.scrollTop||document.documentElement.scrollTop;
                if(s>H){
                    $("#divFloat").addClass("boxfloat");
                }
                else{
                    $("#divFloat").removeClass("boxfloat");
                }
            });



            function editor_init(){
                editor_api.editor.content.obj=$('#editor_content');
                editor_api.editor.intro.obj=$('#editor_intro');
                editor_api.editor.content.get=function(){return this.obj.val()};
                editor_api.editor.content.put=function(str){return this.obj.val(str)};
                editor_api.editor.content.focus=function(){return this.obj.focus()};
                editor_api.editor.intro.get=function(){return this.obj.val()};
                editor_api.editor.intro.put=function(str){return this.obj.val(str)};
                editor_api.editor.intro.focus=function(){return this.obj.focus()};
                sContent=editor_api.editor.content.get();
            }

        </script>

        <script type="text/javascript">

            var EditorIntroOption = {
                toolbars:[['Source', 'bold', 'italic','link','insertimage','Undo', 'Redo']],
                autoHeightEnabled:false,
                initialFrameHeight:200
            }


            function getContent(){
                return editor_api.editor.content.get();
            }

            function getIntro(){
                return editor_api.editor.intro.get();
            }

            function setContent(s){
                editor_api.editor.content.put(s);
            }

            function setIntro(s){
                editor_api.editor.intro.put(s);
            }

            function editor_init(){

                editor_api.editor.content.obj=UE.getEditor('editor_content');
                editor_api.editor.intro.obj=UE.getEditor('editor_intro',EditorIntroOption);
                editor_api.editor.content.get=function(){return this.obj.getContent()};
                editor_api.editor.content.put=function(str){return this.obj.setContent(str)};
                editor_api.editor.content.focus=function(){return this.obj.focus()};
                editor_api.editor.intro.get=function(){return this.obj.getContent()};
                editor_api.editor.intro.put=function(str){return this.obj.setContent(str)};
                editor_api.editor.intro.focus=function(){return this.obj.focus()};


                editor_api.editor.content.obj.ready(function(){sContent=editor_api.editor.content.get();});
                editor_api.editor.intro.obj.ready(function(){sIntro=editor_api.editor.intro.get();});

                $(document).ready(function(){
                    $('#edit').submit(function(){if(editor_api.editor.content.obj.queryCommandState('source')==1) editor_api.editor.content.obj.execCommand('source');
                        if(editor_api.editor.intro.obj.queryCommandState('source')==1) editor_api.editor.intro.obj.execCommand('source');})
                    /*源码模式下保存时必须切换*/


                    if (("http://" + bloghost + "/").indexOf(location.host.toLowerCase()) < 0)
                        alert("您设置了域名固化，请使用" + bloghost + "访问或进入后台修改域名，否则图片无法上传。");
                });

            }
        </script>
        <script type="text/javascript">editor_init();</script>
    </div>
</section>